<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="../images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">

</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" style="background: #f7f8fc">
        <div class="layui-col-sm12 layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15" style="background: #f7f8fc" id="exam-list">

    </div>
</div>

</body>
<script type="text/javascript"  src="../lib/layui/layui.js"></script>
<script type="text/javascript" src="../js/xadmin.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    layui.use(['element', "form", 'jquery', 'layer'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        get_all_exam()
    });

    function get_all_exam() {
        $.ajax({
            url: 'get_all_exam',
            dataType: "json",//数据格式
            type: "post",//请求方式
            async: false,//是否异步请求
            success: function (data) {
                if (data.code === 200) {
                    var text = ""
                    for (let i = 0; i < data.result.length; i++) {
                        text += "<div class=\"layui-col-sm12 layui-col-md4\">" +
                            "            <div class=\"layui-card\">" +
                            "                <div class=\"layui-card-header\">" +
                            "                    <span style=\"float: left\">" + data.result[i].e_name + "</span>" +
                            "                    <span style=\"float: right\"><a href=\"#\" onclick='del_exam_e_id(" + data.result[i].e_id + ")'><i class=\"layui-icon layui-icon-delete\"></i>删除</a></span>" +
                            "                </div>" +
                            "   <div class=\"layui-card-body\">" +
                            "       <br><span style='font-size: 18px'>试卷名:"+data.result[i].examPaper.ep_name+"</span><br><br>" +
                            "       <span style='font-size: 13px'>考试时间:"+data.result[i].e_begin_time+"至"+data.result[i].e_end_time+"</span><br>" +
                            "       </div>"+
                            "                <div class=\"layui-card-header\" style='text-align: right'>" +
                            "<a class=\"layui-btn layui-btn-normal layui-btn-sm\" onclick=\"get_exam_user_by_e_id('"+data.result[i].e_id+"','"+data.result[i].e_name+"')\">查看详细</a>" +
                            "                </div>" +
                            "            </div>" +
                            "        </div>"
                    }
                    $("#exam-list").html(text)
                }
            },
            error: function (e) {
                alert("出现错误！！");
            }
        });
    }


    function del_exam_e_id(e_id) {
        layer.confirm('确定删除?', {icon: 0}, function () {
            $.ajax({
                url: 'del_exam_e_id',
                dataType: 'json',//数据格式
                type: 'post',//请求方式
                async: false,//是否异步请求
                data: {e_id: e_id},
                success: function (data) {
                    if (data.code === 200) {
                        layer.msg(data.message, {icon: 6, time: 1000}, function () {
                            get_all_exam();
                        });
                    } else {
                        layer.msg(data.message, {icon: 5, time: 1000})
                    }
                },
                error: function (e) {
                    alert("出现错误！！");
                }
            });
        })
    }

    function get_exam_user_by_e_id(e_id,e_name) {
        parent.xadmin.add_tab(e_name, 'exam_user_list?e_id=' + e_id);
    }
</script>

</html>